package com.lancoo.klgcourseware.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.android.tu.loadingdialog.LoadingDialog;
import com.lancoo.klgcourseware.R;
import com.lancoo.klgcourseware.base.BaseKlgActivity;
import com.lancoo.klgcourseware.entity.ExpressPracticeModel;
import com.lancoo.klgcourseware.entity.MoreSlideMenuModel;
import com.lancoo.klgcourseware.entity.WordArticulation;
import com.lancoo.klgcourseware.entity.bean.KlgCommonBean;
import com.lancoo.klgcourseware.entity.bean.KlgDbConstant;
import com.lancoo.klgcourseware.manager.KlgLocalMediaManager;
import com.lancoo.klgcourseware.ui.fragment.basicTrain.BasicTrainBaseFragment;
import com.lancoo.klgcourseware.ui.fragment.pronounceTrain.PronounceBaseFragment;
import com.stkouyu.LancooSkEgnManager;
import com.stkouyu.entity.LgEvaluateObj;

import java.io.IOException;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by pengmi on 2019/8/19 15:41
 * Description:训练界面基类，存放一些公共弹窗，便于后期训练界面扩展
 */
public abstract class KlgBaseTrainActivity extends BaseKlgActivity {

    private static final String TAG = "KlgBaseTrainActivity";

    public static final String KEY_TRAINTAG="trainTag";
    public static final int TRAIN_LEVEL=0;//0--初级，1--中级，2--高级
    public static final int TRAIN_LEVEL_JUNIOR=0;//0--初级，1--中级，2--高级
    public static final int TRAIN_LEVEL_MIDDLE=1;//0--初级，1--中级，2--高级
    public static final int TRAIN_LEVEL_HIGH=2;//0--初级，1--中级，2--高级
    public static final int REQUEST_TO_MORE = 0x70; //进入更多
    protected boolean isLoadSuccess,enableShowPauseDialog=true,isActiviyBackForReuslt,enableDripContinue,haiTrainRecord,isCountTimePause,isSoundPoolLoad,isStartTrain;
    private AlertDialog restAlertDialog,countTimeDialog,evaluationErrorDialog;
    protected String currentTrainTag= BasicTrainBaseFragment.TRAINTAG_SPELL;
    private TextView tv_countTime,tv_countTimeDescription;
    private TimerTask timerTask_countTime,timerTask_studyTime;//倒计时,作答时长计时
    private Timer timer_countTime,timer_studyTime;
    protected int countTime=3,studyTime,countTimeMills;//3，2，1倒计时，训练时长
    private KlgLocalMediaManager dripMedia;
    private LoadingDialog evaluationDialog;
    private SoundPool soundPool;
    private int voiceId, playId;
    protected long startTime;

    @Override
    public void onClick(View v) {
        super.onClick(v);
        int id=v.getId();
        if(id==R.id.tv_dialog_continue_retrain){//继续训练
            dismissDialog();
            continueTrain();
//            startStudyTimeTimer();
        }else if(id==R.id.tv_dialog_retrain){//重新训练
            dismissDialog();
            reTrainStart();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        pauseCountTimeTimer();
        pauseStudyTimeTimer();
        stopSpeechEvaluation(false);
        dismissDialog();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        destroyCountTimeTimer();
        destroyStudyTimeTimer();
        if(dripMedia!=null){
            dripMedia.release();
        }
        if(soundPool!=null){
            soundPool.release();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e("aaaaa","onResume:"+enableShowPauseDialog);
        if(!isLoadSuccess){
            Log.e("aaaaa","onResume,"+isLoadSuccess);
            return;
        }
        if(!enableShowPauseDialog){
            Log.e("aaaaa","onResume,"+enableShowPauseDialog);
            return;
        }
        if(isActiviyBackForReuslt){
            isActiviyBackForReuslt=false;
            Log.e("aaaaa","onResume,"+isActiviyBackForReuslt);
            return;
        }
        showTrainPauseDialog();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e(TAG,"onActivityResult,requestCode:"+requestCode+",resultCode:"+resultCode);
        isActiviyBackForReuslt=true;
        enableShowPauseDialog=true;
        Log.e("aaaaa","onActivityResult:"+enableShowPauseDialog);

    }

    /*********************定时器区域*******************************/


    protected void initCountTimeTimer(){
        timerTask_countTime = new TimerTask() {
            @Override
            public void run() {
                countTime--;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(isCountTimePause){
                            return;
                        }
                        countTimeMills+=20;
                        updateCountTimeProgress(Math.min(countTimeMills,3500),3500);
                        if(countTimeMills==3500){//倒计时0s时开启作答时长统计
                            startStudyTimeTimer();
                            destroyCountTimeTimer();
                            dismissDialog();
                            startDripMusic();
                            return;
                        }
                    }
                });
            }
        };
        timer_countTime = new Timer();
    }

    protected void destroyCountTimeTimer(){
        if(timer_countTime !=null){
            timer_countTime.cancel();
            timer_countTime =null;
        }
        if(timerTask_countTime !=null){
            timerTask_countTime.cancel();
            timerTask_countTime =null;
        }
    }

    protected void startCountTimeTimer(){
        Log.e("aaaaa","启动3s倒计时");
        countTimeMills=0;
        isCountTimePause=false;
        destroyCountTimeTimer();
        initCountTimeTimer();
        timer_countTime.schedule(timerTask_countTime,20,20);
        startTimerMusic();
    }

    protected void pauseCountTimeTimer(){
        isCountTimePause=true;
        if(timer_countTime !=null){
            timer_countTime.cancel();
        }
        if(timerTask_countTime!=null){
            timerTask_countTime.cancel();
        }

    }

    /****作答时长计时器****/

    protected void initStudyTimeTimer(){
        timerTask_studyTime = new TimerTask() {
            @Override
            public void run() {
                studyTime++;
            }
        };
        timer_studyTime = new Timer();
    }

    protected void destroyStudyTimeTimer(){
        if(timer_studyTime !=null){
            timer_studyTime.cancel();
            timer_studyTime =null;
        }
        if(timerTask_studyTime !=null){
            timerTask_studyTime.cancel();
            timerTask_studyTime =null;
        }
    }

    protected void startStudyTimeTimer(){
        destroyStudyTimeTimer();
        initStudyTimeTimer();
        timer_studyTime.schedule(timerTask_studyTime,1000,1000);
    }

    protected void pauseStudyTimeTimer(){
        if(timer_studyTime !=null){
            timer_studyTime.cancel();
        }
        pauseDripMusic();
        pauseTimerMusic();
    }



    /************************音频控制区域*****************************/

    /**
     * 初始化滴水音频
     */
    protected void initDripSound(){
        if(dripMedia==null){
            dripMedia = new KlgLocalMediaManager(this);
            try {
                AssetFileDescriptor assetFileDescriptor = getAssets().openFd("klg_drip_music.mp3");
                dripMedia.setUpMedia(assetFileDescriptor, new KlgLocalMediaManager.OnPlayListener() {
                    @Override
                    public void onComplete() {
                        if(!enableDripContinue){
                            return;
                        }
                        startTrainAfterCountTime();
                    }

                    @Override
                    public void onStartError() {

                    }

                    @Override
                    public void onPausePlay() {

                    }

                    @Override
                    public void onSourceError() {

                    }

                    @Override
                    public void onResumePlay() {

                    }

                    @Override
                    public void onStopPlay() {

                    }

                    @Override
                    public void onPrepare() {

                    }

                    @Override
                    public void onBufferingUpdate(MediaPlayer mp, int percent) {

                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    protected void initTimerMusic(){
        //sdk版本21是SoundPool 的一个分水岭
        if (Build.VERSION.SDK_INT >= 21) {
            SoundPool.Builder builder = new SoundPool.Builder();
            //传入最多播放音频数量,
            builder.setMaxStreams(1);
            //AudioAttributes是一个封装音频各种属性的方法
            AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
            //设置音频流的合适的属性
            attrBuilder.setLegacyStreamType(AudioManager.STREAM_MUSIC);
            //加载一个AudioAttributes
            builder.setAudioAttributes(attrBuilder.build());
            soundPool = builder.build();
        } else {
            /**
             * 第一个参数：int maxStreams：SoundPool对象的最大并发流数
             * 第二个参数：int streamType：AudioManager中描述的音频流类型
             *第三个参数：int srcQuality：采样率转换器的质量。 目前没有效果。 使用0作为默认值。
             */
            soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
        }

        //可以通过四种途径来记载一个音频资源：
        //1.通过一个AssetFileDescriptor对象
        //int load(AssetFileDescriptor afd, int priority)
        //2.通过一个资源ID
        //int load(Context context, int resId, int priority)
        //3.通过指定的路径加载
        //int load(String path, int priority)
        //4.通过FileDescriptor加载
        //int load(FileDescriptor fd, long offset, long length, int priority)
        //声音ID 加载音频资源,这里用的是第二种，第三个参数为priority，声音的优先级*API中指出，priority参数目前没有效果，建议设置为1。
        voiceId = soundPool.load(this, R.raw.klg_timer_music, 1);
        //异步需要等待加载完成，音频才能播放成功
        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                Log.e("aaaa","soundPool 加载完毕");
                isSoundPoolLoad=true;
                if(isFinishing()||isCountTimePause){
                    return;
                }
                if(isStartTrain){
                    startTrainCountTime(0);
                }
                if (status == 0) {
                }
            }
        });

    }

    private void startDripMusic(){
        Log.e(TAG, "startDripMusic: "  );
        enableDripContinue=true;
        if(dripMedia!=null){
            dripMedia.start();
        }
    }

    private void pauseDripMusic(){
        enableDripContinue=false;
        if(dripMedia!=null){
            dripMedia.pause();
        }
    }

    private void startTimerMusic(){
        if(soundPool!=null){
            playId=soundPool.play(voiceId, 1, 1, 1, 2, 1);
        }
    }

    protected void pauseTimerMusic(){
        Log.e("aaaa","暂停3s音频");
        if(soundPool!=null){
            soundPool.pause(playId);
        }
    }

    /*********************语音评测*************************/

    /**
     * 开始语音评测
     */
    private void startSpeechEvaluation(String evaluationContent,String url){
        Log.e("aaaaaaaaaa","开始音频评测，"+evaluationContent);
        LancooSkEgnManager.getInstance(this).startRecord(evaluationContent,url,new LancooSkEgnManager.OnLancooRecordListener(){
            @Override
            public void onRecordStart() {

            }

            @Override
            public void onRecording(int vad_status, int sound_intensity) {
                Log.e("pmp","onRecording:"+sound_intensity);
            }

            @Override
            public void onRecordEnd(final int grade,final String url,final LgEvaluateObj skegnResult) {
                Log.e("pmp","onRecordEnd");
                if(isFinishing()){
                    return;
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(isFinishing()){
                            return;
                        }
                        if(evaluationDialog!=null&&evaluationDialog.isShowing()){
                            evaluationDialog.dismiss();
                        }
                        onEvaluationSuccessCallBack(grade,url,skegnResult);
                    }
                });

//                onEvaluationSuccessCallBack(100,url,skegnResult);
            }

            @Override
            public void onRecordError(String error) {
                Log.e("pmp","onRecordError:"+error);
                showEvaluationErrorDialog();
            }

            @Override
            public void onRecordStop() {

            }
        });
    }


    protected void stopSpeechEvaluation(boolean isCallBack){
        LancooSkEgnManager.getInstance(this).stopRecord(isCallBack);
        if(!isCallBack){
            if(evaluationDialog!=null&&evaluationDialog.isShowing()){
                evaluationDialog.dismiss();
            }
        }else{
            if(evaluationDialog==null){
                LoadingDialog.Builder builder=new LoadingDialog.Builder(this);
                builder.setCancelable(false);
                builder.setMessage(getString(R.string.klg_evaluation_wait));
                evaluationDialog = builder.create();
            }
//            evaluationDialog.show();
        }
    }





    /********************dialog区域*****************************/

    /**
     * 作答训练中断流程弹窗
     */
    protected void showTrainPauseDialog(){
        pauseCurrentTrainProgress();
        if(restAlertDialog==null){
            AlertDialog.Builder builder=new AlertDialog.Builder(this, R.style.klg_NoBgColorStyle);
            View inflate = LayoutInflater.from(this).inflate(R.layout.klg_dialog_pause_train, null);
            builder.setView(inflate);
            builder.setCancelable(false);
            restAlertDialog = builder.create();
            inflate.findViewById(R.id.tv_dialog_continue_retrain).setOnClickListener(this);
            inflate.findViewById(R.id.tv_dialog_retrain).setOnClickListener(this);

        }
        if(!restAlertDialog.isShowing()){
            restAlertDialog.show();
        }
    }


    /**
     * 倒计时弹窗显示，并开启3，2，1s倒计时
     */
    private void showCountTimeDialog(){
        if(!isSoundPoolLoad){
            return;
        }
        haiTrainRecord=true;
        initDripSound();
        countTime=3;
        countTimeMills=0;
        startCountTimeTimer();
    }

    protected void showEvaluationErrorDialog(){
        if(isFinishing()){
            return;
        }
        if(evaluationDialog!=null&&evaluationDialog.isShowing()){
            evaluationDialog.dismiss();
        }
        pauseCurrentTrainProgress();
        enableShowPauseDialog=false;
        Log.e("aaaaa","showEvaluationErrorDialog:"+enableShowPauseDialog);
        if(evaluationErrorDialog==null){
            View inflate = LayoutInflater.from(this).inflate(R.layout.klg_dialog_evaluation_error, null);
            AlertDialog.Builder builder=new AlertDialog.Builder(this,R.style.klg_NoBgColorStyle);
            builder.setCancelable(false);
            builder.setView(inflate);
            evaluationErrorDialog = builder.create();
            inflate.findViewById(R.id.tv_end_train).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    evaluationErrorDialog.dismiss();
                    finish();
                }
            });
        }
        if(!evaluationErrorDialog.isShowing()){
            evaluationErrorDialog.show();
        }


    }


    private void dismissDialog(){
        if(restAlertDialog!=null&&restAlertDialog.isShowing()){
            restAlertDialog.dismiss();
        }
        if(countTimeDialog!=null&&countTimeDialog.isShowing()){
            countTimeDialog.dismiss();
        }

        if(evaluationDialog!=null&&evaluationDialog.isShowing()){
            evaluationDialog.dismiss();
        }

    }

    /**
     * 暂停当前训练流程训练
     */
    protected void pauseCurrentTrainProgress(){}

    /**
     * 继续训练
     */
    protected void continueTrain(){ }

    /**
     * 重新训练（从第0个模块开始）
     */
    protected void reTrainStart(){}

    /**
     * 从倒计时弹窗关闭滴水音频播放后后开始训练
     */
    protected void startTrainAfterCountTime(){}

    /**
     * 语音评测成功回调
     * @param grade 评测总得分
     * @param url 录音url
     * @param skegnResult 评测详情
     */
    protected void onEvaluationSuccessCallBack(int grade, String url, LgEvaluateObj skegnResult){}


    /**
     * 是否跟当前模式想匹配
     * @param trainTag 训练模式
     * @param isForceShow 是否强制显示引导页
     * @return
     */
    protected boolean isCurrentTrainModel(String trainTag,boolean isForceShow){
        if(!TextUtils.isEmpty(getIntent().getStringExtra(KEY_TRAINTAG))){
            return true;
        }
        if(TextUtils.isEmpty(currentTrainTag)||TextUtils.isEmpty(trainTag)){
            Log.e("aaaa","isCurrentTrainModel。。。直接返回了。。。"+currentTrainTag);
            return false;
        }else{
            Log.e("aaaa","isCurrentTrainModel。。。进来了。。。"+currentTrainTag);
            Log.e("aaaaa","isCurrentTrainModel:"+enableShowPauseDialog);
            enableShowPauseDialog=true;
            if(TextUtils.equals(trainTag,BasicTrainBaseFragment.TRAINTAG_SPELL)&&TextUtils.equals(trainTag,currentTrainTag)){
                //单词拼读
                SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
                boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_SPELL_TRAIN, false);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                if(!enableAutoTrain||isForceShow){
                    haiTrainRecord=false;
                    edit.putBoolean(KlgDbConstant.SP_ALERT_SPELL_TRAIN,true);
                    edit.commit();
                    showSpellTrainOperateAlertDialog(isForceShow);
                }
                return enableAutoTrain;
            }else if(TextUtils.equals(trainTag,BasicTrainBaseFragment.TRAINTAG_USAGE)&&TextUtils.equals(trainTag,currentTrainTag)){
                //读句填空
                SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
                boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_USAGE_TRAIN, false);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                if(!enableAutoTrain||isForceShow){
                    haiTrainRecord=false;
                    edit.putBoolean(KlgDbConstant.SP_ALERT_USAGE_TRAIN,true);
                    edit.commit();
                    showUsageTrainOperateAlertDialog();
                }
                return enableAutoTrain;
            }else if(TextUtils.equals(trainTag,BasicTrainBaseFragment.TRAINTAG_SPELL_MEMORY_WRITE)&&TextUtils.equals(trainTag,currentTrainTag)){
                //全拼默写
                SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
                boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_SPELL_MEMORY_WRITE_TRAIN, false);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                if(!enableAutoTrain||isForceShow){
                    haiTrainRecord=false;
                    edit.putBoolean(KlgDbConstant.SP_ALERT_SPELL_MEMORY_WRITE_TRAIN,true);
                    edit.commit();
                    showSpellMemoryWriteTrainOperateAlertDialog(isForceShow);
                }
                return enableAutoTrain;
            }else if(TextUtils.equals(trainTag,BasicTrainBaseFragment.TRAINTAG_SPELL_FILL)&&TextUtils.equals(trainTag,currentTrainTag)){
                //填空拼写
                SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
                boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_SPELL_FILL_TRAIN, false);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                if(!enableAutoTrain||isForceShow){
                    haiTrainRecord=false;
                    showSpellFillTrainOperateAlertDialog(isForceShow);
                    edit.putBoolean(KlgDbConstant.SP_ALERT_SPELL_FILL_TRAIN,true);
                    edit.commit();
                }
                return enableAutoTrain;
            }else if(TextUtils.equals(trainTag,BasicTrainBaseFragment.TRAINTAG_PHONETIC)&&TextUtils.equals(trainTag,currentTrainTag)){
                SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
                boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_PHONETIC_TRAIN, false);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                if(!enableAutoTrain||isForceShow){
                    haiTrainRecord=false;
                    edit.putBoolean(KlgDbConstant.SP_ALERT_PHONETIC_TRAIN,true);
                    edit.commit();
                    showPhoneticTrainOperateAlertDialog();
                }
                return enableAutoTrain;
            }else if(TextUtils.equals(trainTag,BasicTrainBaseFragment.TRAINTAG_PHONETIC_PHRASE)&&TextUtils.equals(trainTag,currentTrainTag)){
                //词组，esp发音训练
                SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
                boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_PHONETIC_PHRASE_TRAIN, false);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                if(!enableAutoTrain||isForceShow){
                    haiTrainRecord=false;
                    edit.putBoolean(KlgDbConstant.SP_ALERT_PHONETIC_PHRASE_TRAIN,true);
                    edit.commit();
                    showPhoneticTrainOperateAlertDialog();
                }
                return enableAutoTrain;
            }else if(TextUtils.equals(trainTag,BasicTrainBaseFragment.TRAINTAG_LISTEN_REPEAT)&&TextUtils.equals(trainTag,currentTrainTag)){
                //听音复述
                SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
                boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_PHONETIC_REPEAT_TRAIN, false);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                if(!enableAutoTrain||isForceShow){
                    haiTrainRecord=false;
                    edit.putBoolean(KlgDbConstant.SP_ALERT_PHONETIC_REPEAT_TRAIN,true);
                    edit.apply();
                    showRepeatTrainOperateAlertDialog();
                }
                return enableAutoTrain;
            }
            return TextUtils.equals(trainTag,currentTrainTag);
        }
    }

    /**
     * 根据知识点Code倒数第4位获取训练级别
     * @param klgCode
     * @return
     */
    protected int getTrainLevel(String klgCode){
        SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE,Context.MODE_PRIVATE);
        int trainLevel = sharedPreferences.getInt(KlgDbConstant.SP_TRAIN_LEVEL, -1);
        if(trainLevel!=-1){
            return trainLevel;
        }
        if(TextUtils.isEmpty(klgCode)){
            return TRAIN_LEVEL_JUNIOR;
        }else if(klgCode.length()>3){
            Log.e("aaaaa","getTrainLevel:"+klgCode+"..."+klgCode.substring(klgCode.length()-4,klgCode.length()-3));
            switch (klgCode.substring(klgCode.length()-4,klgCode.length()-3)){
                case "A"://小学
                    return TRAIN_LEVEL_JUNIOR;
                case "B"://初中
                    return TRAIN_LEVEL_JUNIOR;
                case "C"://高中
                    return TRAIN_LEVEL_MIDDLE;
                case "D"://中职
                    return TRAIN_LEVEL_JUNIOR;
                case "E"://高职
                    return TRAIN_LEVEL_MIDDLE;
                case "F": //大学公共英语
                    return TRAIN_LEVEL_HIGH;
                case "H"://大学英语专业
                    return TRAIN_LEVEL_HIGH;
                case "J"://研究生公共英语
                    return TRAIN_LEVEL_HIGH;
                default:
                    return TRAIN_LEVEL_JUNIOR;
            }
        }else{
            return TRAIN_LEVEL_JUNIOR;
        }

    }


    protected void dismissEvaluationDialog(){
        if(evaluationDialog!=null&&evaluationDialog.isShowing()){
            evaluationDialog.dismiss();
        }
    }

    /**
     * 进入下个训练模式
     */
    protected void enterNextTrainModel(){}

    protected KlgCommonBean getKlgCommonBean(){
        return null;
    }

    /**
     * 进入下一个子模式训练
     */
    protected void enterPronounceSubTrainModel(PronounceBaseFragment.PronounceState pronounceState){}

    /**
     * 重新开始用法训练
     */
    protected void resetUsageTrain(){}

    /**
     * 3，2，1倒计时的进度
     * @param progress
     */
    protected void updateCountTimeProgress(int progress,int totalProgress){}

    /**
     * 展示单词拼读操作引导图
     * @param isOnlyShowSpellAlert
     */
    protected void showSpellTrainOperateAlertDialog(boolean isOnlyShowSpellAlert){}

    /**
     * 展示发音训练操作引导图
     */
    protected void showPhoneticTrainOperateAlertDialog(){}

    /**
     * 展示用法训练操作引导图
     */
    protected void showUsageTrainOperateAlertDialog(){}

    /**
     * 展示全拼默写训练操作引导图
     */
    protected void showSpellMemoryWriteTrainOperateAlertDialog(boolean isOnlyShowSpellAlert){}

    /**
     * 展示填空拼写训练操作引导图
     */
    protected void showSpellFillTrainOperateAlertDialog(boolean isOnlyShowSpellAlert){}

    /**
     * 展示听音复述训练操作引导图
     */
    protected void showRepeatTrainOperateAlertDialog(){}

    /**
     * 更新作答过关结果
     */
    protected void updateCurrentTrainResult(boolean isQuality,float grade){}



    /************************对外访问方法*******************************/
    public boolean enableStartTrain(String trainTag){
        return isCurrentTrainModel(trainTag,false);
    }

    public void startTrainCountTime(int alertMsgId){
        isStartTrain=true;//开启训练了
        showCountTimeDialog();
    }

    public void startSpeechEvaluationEngine(String evaluationContent,String url){
        startSpeechEvaluation(evaluationContent,url);
    }

    /**
     * 停止语音评测
     */
    public void stopSpeechEvaluationEngine(boolean isCallBack){
        stopSpeechEvaluation(isCallBack);
    }

    /**
     * 开始下一个模式训练
     */
    public void startNextTrainModel(){
        enterNextTrainModel();
    }

    public void changeEnableShowPauseTrainDialogState(boolean enableShowPauseDialog){
        Log.e("aaaaa","changeEnableShowPauseTrainDialogState:"+enableShowPauseDialog);
        this.enableShowPauseDialog=enableShowPauseDialog;
    }

    /**
     * 播放滴水音频
     */
    public void playDripMusic(){
        startDripMusic();
    }

    /**
     * 暂停滴水音频
     */
    public void pauseDripMusicPlay(){
        pauseDripMusic();
    }

    public void enterPronounceTrainResultActivity(int score, List<String> recordList,String resultModel){
//        enableShowPauseDialog=false;
        destroyStudyTimeTimer();
//        PronounceResultActivity.launch(this,getKlgCommonBean(),score,studyTime,resultModel,recordList);
        enterNextTrainModel();
    }

    public void enterUsageTrainResultActivity(WordArticulation wordArticulation, List<MoreSlideMenuModel> trainRecordList, List<ExpressPracticeModel> expressPracticeModelList){
        destroyStudyTimeTimer();
        TrainResultActivity.launch(this,getKlgCommonBean(),wordArticulation,expressPracticeModelList,trainRecordList,studyTime);
    }

    public void pauseThreeSecondTimer(){
        pauseDripMusic();
        pauseCountTimeTimer();
        pauseTimerMusic();
    }

    /**
     * 更新作答结果
     * @param isQuality
     */
    public void upDateTrainRecordResult(boolean isQuality,float grade){
        updateCurrentTrainResult(isQuality,grade);
    }

    /**
     * 我不练了
     */
    public void giveUpTrain(){
        onBackPressed();
    }


}
